package com.thwcompany.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by IntelliJ IDEA2021.3
 *
 * @Author: Tenghw
 * @Date: 2022/10/21  20:00
 * @Description: 死信交换机、死信队列都是一种特殊的交换机、队列
 */
@Configuration
@SuppressWarnings("all")
public class DeadLetterRabbitMQConfig {
    //创建死信交换机
    @Bean
    public DirectExchange deadLetterExchange(){
        return new DirectExchange("dead.letter.exchange",true,false);
    }

    //创建死信队列
    @Bean
    public Queue deadLetterQueue() {
        return new Queue("dead.letter.queue",true,false,false,null);
    }

    // 死信队列和死信交换机通过路由键绑定
    @Bean
    Binding deadLetterBinding() {
        return BindingBuilder.bind(deadLetterQueue()).to(deadLetterExchange()).with("dead.letter");
    }
}
